home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 August / macformat-027.iso / mac / Shareware City / Developers / Oberon⁄F / Text / Docu / Rulers (.txt) < prev    next >
Encoding:
Oberon Document  |  1994-06-07  |  15.1 KB  |  310 lines  |  [oODC/obnF]

  1. Documents.StdDocumentDesc
  2. Documents.DocumentDesc
  3. Containers.ViewDesc
  4. Views.ViewDesc
  5. Stores.StoreDesc
  6. Documents.ModelDesc
  7. Containers.ModelDesc
  8. Models.ModelDesc
  9. Stores.ElemDesc
  10. TextViews.StdViewDesc
  11. TextViews.ViewDesc
  12. TextModels.StdModelDesc
  13. TextModels.ModelDesc
  14. TextModels.AttributesDesc
  15. Geneva
  16. TextRulers.StdRulerDesc
  17. TextRulers.RulerDesc
  18. TextRulers.StdStyleDesc
  19. TextRulers.StyleDesc
  20. TextRulers.AttributesDesc
  21. Geneva
  22. Geneva
  23. Geneva
  24. 6.3 TextRulers
  25. DEFINITION TextRulers;
  26.     IMPORT Stores, Models, Views, Dialog, Properties, TextModels;
  27.     CONST
  28.         first = 0; left = 1; right = 2; lead = 3; asc = 4; dsc = 5; grid = 6; opts = 7; tabs = 8;
  29.         leftAdjust = 0; rightAdjust = 1; noBreakInside = 2; pageBreak = 3; parJoin = 4;
  30.     TYPE
  31.         Attributes = POINTER TO AttributesDesc;
  32.         AttributesDesc = RECORD (Stores.StoreDesc)
  33.             first-, left-, right-, lead-, asc-, dsc-, grid-: LONGINT;
  34.             opts-: SET;
  35.             tabs-: INTEGER;
  36.             tab-: ARRAY 32 OF LONGINT;
  37.             PROCEDURE (a: Attributes) Clone (): Attributes;
  38.             PROCEDURE (a: Attributes) InitFromProp (p: Properties.Property);
  39.             PROCEDURE (a: Attributes) ModifyFrom (source: Attributes; p: Properties.Property);
  40.             PROCEDURE (a: Attributes) Equals (b: Attributes): BOOLEAN;
  41.             PROCEDURE (a: Attributes) Prop (): Properties.Property
  42.         END;
  43.         AlienAttributes = POINTER TO AlienAttributesDesc;
  44.         AlienAttributesDesc = RECORD (AttributesDesc)
  45.             store-: Stores.Alien
  46.         END;
  47.         Style = POINTER TO StyleDesc;
  48.         StyleDesc = RECORD (Models.ModelDesc)
  49.             attr-: Attributes;
  50.             PROCEDURE (s: Style) Clone (): Style;
  51.             PROCEDURE (s: Style) SetAttr (attr: Attributes);
  52.             PROCEDURE (s: Style) CopyFrom (source: Style)
  53.         END;
  54.         Ruler = POINTER TO RulerDesc;
  55.         RulerDesc = RECORD (Views.ViewDesc)
  56.             style-: Style;
  57.             PROCEDURE (r: Ruler) Clone (): Ruler;
  58.             PROCEDURE (r: Ruler) InitStyle (style: Style);
  59.         END;
  60.         Options = RECORD (Dialog.Selection) END;
  61.         TabArray = RECORD (Dialog.Array)
  62.             tab: ARRAY 32 OF Dialog.Units
  63.         END;
  64.         Prop = POINTER TO PropDesc;
  65.         PropDesc = RECORD (Properties.PropertyDesc)
  66.             first, left, right, lead, asc, dsc, grid: Dialog.Units;
  67.             opts: Options;
  68.             tabs: TabArray
  69.         END;
  70.         UpdateMsg = RECORD (Models.UpdateMsg)
  71.             style: Style;
  72.             oldAttr: Attributes
  73.         END;
  74.         Directory = POINTER TO DirectoryDesc;
  75.         DirectoryDesc = RECORD
  76.             attr-: Attributes;
  77.             PROCEDURE (d: Directory) SetAttr (attr: Attributes);
  78.             PROCEDURE (d: Directory) NewStyle (attr: Attributes): Style;
  79.             PROCEDURE (d: Directory) New (style: Style): Ruler;
  80.             PROCEDURE (d: Directory) NewFromProp (p: Prop): Ruler;
  81.             PROCEDURE (d: Directory) StdNew (): Ruler
  82.         END;
  83.     VAR dir-, stdDir-: Directory;
  84.     PROCEDURE ReadAttr (VAR rd: Stores.Reader; VAR a: Attributes);
  85.     PROCEDURE WriteAttr (VAR wr: Stores.Writer; a: Attributes);
  86.     PROCEDURE CopyOf (r: Ruler; shallow: BOOLEAN): Ruler;
  87.     PROCEDURE GetValidRuler (text: TextModels.Model; pos, hint: LONGINT;
  88.                                                 VAR ruler: Ruler; VAR rpos: LONGINT);
  89.     PROCEDURE Deposit;
  90.     PROCEDURE SetDir (d: Directory);
  91. END TextRulers.
  92. TextRulers are text
  93. aware views that, if embedded in a text, affect the text setting. A ruler supports interactive and program controlled adjustment of paragraph and limited page formatting. However, the ruler does not perform the actual setting of the text according to the format defined by the ruler. Text setters are used to actually set a text (cf. Section 6.4).
  94. CONST first, left, right, lead, asc, dsc, grid, opts, tabs
  95. Property field selectors
  96. Signals that the named field of a Prop property is known, valid, or readOnly.
  97. CONST leftAdjust, rightAdjust
  98. Possible elements of Attributes.opts. If none is included, request centered lines; if leftAdjust is included alone, request left flushed lines; if rightAdjust is included alone, request right flushed lines; if both are included, request fully adjusted lines.
  99. CONST noBreakInside, pageBreak, parJoin
  100. Possible elements of Attributes.opts, where the inclusion of pageBreak overrides a possible inclusion of parJoin. If noBreakInside is included, request setting of the following paragraphs (up to the next ruler or the end of text) such that no page break is crossed by any of the paragraphs; a page break may be inserted between the paragraphs, but see parJoin below. (This may not be possible, or lead to unacceptably large white space, in which case a setter's heuristics may insert page breaks anyways.) If pageBreak is included, request setting to continue on the next fresh page. (If already at the top of a new page, the request is ignored.) If parJoin is included, the paragraph following the ruler is requested to be set on the same page as the paragraph preceding the ruler. (This may cause insertion of a page break in or before the preceding paragraph.)
  101. TYPE Attributes
  102. Extension
  103. The style of a ruler holds an attributes object.
  104. Once created and initialized, attributes objects can no longer be modified, and hence can be freely shared among many ruler styles. Changing the attributes of a style is done by changing the whole attributes object attached to the style. (Styles in turn may be shared by multiple rulers, causing all these rulers to change in synch when changing the attributes of the style.)
  105. first-, left-, right-: LONGINT    [units]
  106. First line indentation of every following paragraph, left margin (other than for first line of a paragraph), and right margin. All measured from the left margin of the view displaying the set text.
  107. lead-: LONGINT    [units]
  108. Vertical lead space inserted before every following paragraph, unless the paragraph happens to start a new page.
  109. asc-, dsc-: LONGINT    [units]
  110. Lower bounds on the ascender and descender of the lines of the following paragraphs.
  111. grid-: LONGINT    [units]    1 <= grid < Views.infinite
  112. Grid spacing (if 1: no grid). Each line of the following paragraphs is set such that its base line falls on a grid line. (Depending on the setter used, this may cause overlaps of high lines, or it may cause higher lines to be moved to the next possible grid line in order to avoid overlaps.)
  113. opts-: SET
  114. Formatting options, drawn from the set {leftAdjust, rightAdjust, noBreakInside, pageBreak, parJoin}. The options noBreakInside and parJoin are requests that, depending on the setter's heuristics, may or may not be followed.
  115. tabs-: INTEGER    0 <= tabs <= 32
  116. tab-: ARRAY 32 OF LONGINT    [units]    tab[0 .. tabs) valid
  117. Tabulator stops measured from the left margin of the view displaying the set text.
  118. PROCEDURE (a: Attributes) Clone (): Attributes
  119. Default, Extension
  120. Result type is narrowed.
  121. PROCEDURE (a: Attributes) CopyFrom (source: Attributes)
  122. Copy attributes from an initialized to a new attributes object.
  123. ~a.init    20
  124. source.init    21
  125. a.init
  126. a.first = source.first
  127. a.left = source.left
  128. a.right = source.right
  129. a.lead = source.lead
  130. a.asc = source.asc
  131. a.dsc = source.dsc
  132. a.grid = source.grid
  133. a.tab = source.tab
  134. a.tabs = source.tabs
  135. PROCEDURE (a: Attributes) Equals (b: Attributes): BOOLEAN
  136. Compare two attributes objects for attribute equality.
  137. a.init    20
  138. b.init    21
  139. result =  TypeOf(a) = TypeOf(b)  &  a.first = b.first  & ... &  a.tabs = b.tabs
  140. PROCEDURE (a: Attributes) Prop (): Properties.Property
  141. Return property list reflecting attribute values.
  142. a.init    20
  143. result # NIL
  144. PROCEDURE (a: Attributes) ModifyFrom (source: Attributes; p: Properties.Property)
  145. Initialize new attributes object to attributes of a source object, but modified according to the property list. (Values valid in the property list are taken from it, others from the source attributes object.)
  146. a.init    20
  147. source.init    21
  148. PROCEDURE (a: Attributes) InitFromProp (p: Properties.Property)
  149. Initialize according to property list.
  150. ~a.init    20
  151. a.init
  152. TYPE AlienAttributes
  153. Extension, Leaf
  154. Type of alien attributes objects, as returned by ReadAttr.
  155. store-: Stores.Alien
  156. The alien store enclosed by an alien attributes objects.
  157. TYPE Style
  158. A style is a ruler model (and thus may be shared my multiple rulers).
  159. attr-: Attributes    style.init => attr # NIL  &  attr # NIL => attr.init
  160. The attributes defining this style's formatting requests.
  161. PROCEDURE (s: Style) Clone (): Style
  162. Default, Extension
  163. Result type is narrowed.
  164. PROCEDURE (s: Style) SetAttr (attr: Attributes)
  165. Default, Operation
  166. Set style attributes.
  167. attr # NIL    (not explicitly checked)
  168. attr.init    20
  169. s'.attr.Equals(attr)
  170.     s.attr = s'.attr
  171. ~s'.attr.Equals(attr)
  172.     s.attr = attr
  173. PROCEDURE (s: Style) CopyFrom (source: Style)
  174. Copy an uninitialized style from a source style.
  175. ~s.init    20
  176. source # NIL    (not explicitly checked)
  177. source.attr # NIL    21
  178. s.init
  179. s.attr = source.attr
  180. TYPE Ruler
  181. Rulers are the standard view on styles.
  182. style-: Style    ruler.init => style # NIL  &  style # NIL => style.init
  183. The ruler's style.
  184. PROCEDURE (r: Ruler) Clone (): Ruler
  185. Default, Extension
  186. Result type is narrowed.
  187. PROCEDURE (r: Ruler) InitStyle (style: Style)
  188. Default
  189. Initialize the ruler's style.
  190. r.style = NIL    20
  191. style # NIL    21
  192. style.attr # NIL    22
  193. r.style = style
  194. PROCEDURE (r: Ruler) InitDomain (d: Domains.Domain)
  195. Default, Extension
  196. Precondition added.
  197. r.style # NIL    20
  198. TYPE Options
  199. Extension
  200. Type of attribute options used in Prop.
  201. TYPE TabArray
  202. Extension
  203. Type of tabulator stop array in Prop.
  204. TYPE Prop
  205. Extension
  206. Properties of style attributes.
  207. first, left, right, lead, asc, dsc, grid: Dialog.Units
  208. opts: Options
  209. tabs: TabArray
  210. Property fields
  211. Each property field corresponds to the attribute field of same name. (Property field tabs corresponds to (tab, tabs) in Attributes.)
  212. TYPE UpdateMsg
  213. Message notifying of a change of attributes attached to a certain style. The message is domaincast and typically interpreted by all text views which display a text that contains a ruler that shares the changed style.
  214. style: Style
  215. The style that has changed.
  216. oldAttr: Attributes
  217. The attributes that were attached to style previously.
  218. TYPE Directory
  219. Directory for rulers and styles.
  220. attr-: Attributes    attr # NIL  &  attr.init
  221. Default attributes used when initializing new style.
  222. PROCEDURE (d: Directory) SetAttr (attr: Attributes)
  223. Default
  224. Set default attributes.
  225. attr # NIL    (not explicitly checked)
  226. attr.init    20
  227. d.attr = attr
  228. PROCEDURE (d: Directory) NewStyle (attr: Attributes): Style
  229. Interface
  230. Return new style object initialized to hold attributes attr.
  231. attr # NIL    20
  232. attr.init    21
  233. result # NIL
  234. result.init
  235. result.attr = attr
  236. PROCEDURE (d: Directory) New (style: Style): Ruler
  237. Interface
  238. Return new ruler object initialized to hold given style.
  239. style # NIL    20
  240. style.init    21
  241. result # NIL
  242. result.init
  243. result.style = style
  244. PROCEDURE (d: Directory) NewFromProp (p: Prop): Ruler
  245. Default
  246. Return new ruler object with style attributes initialized from give property list, using d.attr for default values.
  247. Except for performance, equivalent to:
  248.     VAR a: Attributes;
  249.     a := d.attr.Clone(); a.ModifyFrom(d.attr, p);
  250.     RETURN d.New(d.NewStyle(a))
  251. PROCEDURE (d: Directory) StdNew (): Ruler
  252. Default
  253. Return new ruler with default style and attributes.
  254. Except for performance, equivalent to:
  255.     RETURN d.New(d.NewStyle(d.attr))
  256. VAR dir-, stdDir-: Directory    dir # NIL, stdDir # NIL, stable stdDir = d
  257. Directory and standard directory objects for rulers and styles.
  258. PROCEDURE  ReadAttr (VAR rd: Stores.Reader; VAR a: Attributes)
  259. Read an attributes object; in case the reader returns an alien store, the store is wrapped into an alien attributes object and the wrapper is returned.
  260. ~rd.rider.eof    20
  261. NextStore(rd) IS Attributes    21
  262. a # NIL
  263. ~MapsToAlien(NextStore(rd'))
  264.     a = NextStore(rd')
  265. MapsToAlien(NextStore(rd'))
  266.     a IS AlienAttributes
  267.     a.store = NextStore(rd')
  268. PROCEDURE  WriteAttr (VAR wr: Stores.Writer; a: Attributes)
  269. Read an attributes object; in case the reader returns an alien store, the store is wrapped into an alien attributes object and the wrapper is returned.
  270. a # NIL    20
  271. a.init    21
  272. Except for performance, equivalent to:
  273.     WITH a: AlienAttributes DO wr.WriteStore(a.store) ELSE wr.WriteStore(a) END
  274. PROCEDURE CopyOf (r: Ruler; shallow: BOOLEAN): Ruler
  275. Create [shallow] copy of ruler.
  276. r # NIL    20
  277. Except for performance, equivalent to:
  278.     VAR v: Views.View;
  279.     v := Views.CopyOf(r, shallow); RETURN v(Ruler)
  280. PROCEDURE GetValidRuler (text: TextModels.Model; pos, hint: LONGINT;
  281.                                                     VAR ruler: Ruler; VAR rpos: LONGINT);
  282. Locate the ruler in text that dominates position pos. If a ruler position is known, it can be passed as a hint: (ruler, rpos) is first ruler before hint. Otherwise, pass hint = -1. On return, either the dominating ruler is returned as (ruler, rpos), or ruler and rpos remain unchanged.
  283. hint < 0  OR  rpos = Pos(ruler) &  no ruler in (rpos, hint]  &  0 <= pos <= t.Length()
  284. hint < rpos <= pos  &  rpos = Pos(ruler)  &  no ruler in (rpos, pos]  OR  (ruler, rpos) unmodified
  285. Except for performance, equivalent to:
  286.     VAR view: Views.View; rd: TextModels.Reader;
  287.     IF pos < text.Length() THEN INC(pos) END;    (* let a ruler dominate its own position! *)
  288.     IF pos < hint THEN hint := -1 END;
  289.     rd := text.NewReader(rd); rd.SetPos(pos);
  290.     REPEAT
  291.         rd.ReadPrevView(view)
  292.     UNTIL rd.eot OR (view IS Ruler) OR (rd.Pos() < hint);
  293.     IF (view # NIL) & (view IS Ruler) THEN
  294.         ruler := view(Ruler); rpos := rd.Pos()
  295. PROCEDURE Deposit
  296. Create new ruler and deposit in Views queue.
  297. Except for performance, equivalent to:
  298.     Views.Deposit(dir.StdNew())
  299. PROCEDURE  SetDir (d: Directory)
  300. Set model directory.
  301. d # NIL    20
  302. d.attr # NIL    21
  303. d.attr.init    22
  304. TextControllers.StdCtrlDesc
  305. TextControllers.ControllerDesc
  306. Containers.ControllerDesc
  307. Controllers.ControllerDesc
  308. Geneva
  309. Documents.ControllerDesc
  310.